﻿namespace ExamV5.ManagSys
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmSetUserGroup : Page
    {
        protected Button butClose;
        protected Button butDefault;
        protected HtmlForm form1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        protected int intID = 0;
        protected Label labTipTitle;
        private PublicFun publicFun_0 = new PublicFun();
        private string string_0 = "";
        protected string strReUserCode = "";
        protected string strReUserName = "";

        protected void butDefault_Click(object sender, EventArgs e)
        {
            string str = "";
            string str2 = "";
            str = base.Request.Form["txtBrowUserCode"].ToString();
            str2 = base.Request.Form["txtBrowUserName"].ToString();
            str = "," + str + ",";
            str2 = "," + str2 + ",";
            string strSql = "";
            string str4 = this.string_0.Trim();
            switch (str4)
            {
                case null:
                    break;

                case "E":
                    strSql = string.Concat(new object[] { "Update SubjectInfo set  EditUserCode='", str.Trim(), "',EditUserName='", str2.Trim(), "' where ID=", this.intID });
                    break;

                default:
                    if (str4 != "B")
                    {
                        if (!(str4 == "G"))
                        {
                            if (str4 == "M")
                            {
                                strSql = string.Concat(new object[] { "Update SysMenu set BrowUserCode='", str.Trim(), "',BrowUserName='", str2.Trim(), "' where ID=", this.intID });
                            }
                        }
                        else
                        {
                            strSql = string.Concat(new object[] { "Update UserGroup set  UserCode='", str.Trim(), "',UserName='", str2.Trim(), "' where ID=", this.intID });
                        }
                    }
                    else
                    {
                        strSql = string.Concat(new object[] { "Update SubjectInfo set  BrowUserCode='", str.Trim(), "',BrowUserName='", str2.Trim(), "' where ID=", this.intID });
                    }
                    break;
            }
            this.publicFun_0.ExecuteSql(strSql);
            base.Response.Write("<script>alert('设置用户范围操作成功！');parent.location.reload();</script>");
        }

        private void method_0()
        {
            string cmdText = "";
            switch (this.string_0.Trim())
            {
                case "E":
                    cmdText = "Select EditUserName as UserName,EditUserCode as UserCode from SubjectInfo where ID=" + this.intID;
                    break;

                case "B":
                    cmdText = "Select BrowUserName as UserName,BrowUserCode as UserCode from SubjectInfo where ID=" + this.intID;
                    break;

                case "M":
                    cmdText = "select BrowUserCode as UserCode,BrowUserName as UserName from SysMenu where ID=" + this.intID;
                    break;

                case "G":
                    cmdText = "Select UserName,UserCode from UserGroup where ID=" + this.intID;
                    break;
            }
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlDataReader reader = new SqlCommand(cmdText, connection).ExecuteReader(CommandBehavior.CloseConnection);
            if (reader.Read())
            {
                this.strReUserName = reader["UserName"].ToString();
                this.strReUserCode = reader["UserCode"].ToString();
                if (this.strReUserCode.Trim() != "")
                {
                    this.strReUserCode = this.strReUserCode.Substring(1, this.strReUserCode.Length - 2);
                    this.strReUserName = this.strReUserName.Substring(1, this.strReUserName.Length - 2);
                }
            }
            reader.Close();
            connection.Close();
            connection.Dispose();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 == null) || (this.httpCookie_0.Value == ""))
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
            else
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                this.string_0 = base.Request["Flag"].ToString();
                this.intID = Convert.ToInt32(base.Request["ID"].ToString());
                if (!base.IsPostBack)
                {
                    switch (this.string_0.Trim())
                    {
                        case "E":
                            this.labTipTitle.Text = "设置编辑人员";
                            break;

                        case "B":
                            this.labTipTitle.Text = "设置浏览人员";
                            break;

                        case "M":
                            this.labTipTitle.Text = "设置浏览人员";
                            break;

                        case "G":
                            this.labTipTitle.Text = "设置用户组人员";
                            break;
                    }
                    if (this.publicFun_0.GetValues("select ManagUser from UserPower where UserCode='" + this.httpCookie_0.Value + "'", "ManagUser") != "Y")
                    {
                        this.butDefault.Visible = false;
                    }
                    this.Page.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString;
                    this.method_0();
                }
            }
        }
    }
}

